Skip to content

Fix Security Hub findings at the source of every install - #557

Merged
nambok merged 3 commits into
mainfrom
fix/security-hub
Nov 10, 2026
Merged

nambok merged 3 commits into
mainfrom
fix/security-hub

Conversation

@nambok

@nambok nambok commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

AWS Security Hub flagged a self-hosted install. The most serious finding was Lambda.1 (critical): the streaming function's URL was open to the internet. This PR fixes each finding in the templates every install deploys, and documents the findings left as they are, with the reason (docs/self-host/security.md, "Security Hub"). Every change applies as an in-place update, and no table, bucket, key or user pool is replaced.

Changes

The chat stream (Lambda.1, CloudFront.16)

  • On a single-origin install, the streaming function URL uses AWS_IAM. The public FunctionUrlAuthType NONE permissions are gone.
  • The web distribution reaches the URL through origin access control (FunctionUrlOrigin.withOriginAccessControl: always sign, SigV4). The function's policy allows cloudfront.amazonaws.com for that one distribution, with both lambda:InvokeFunctionUrl and lambda:InvokeFunction (InvokedViaFunctionUrl). The stream behaviours still forward every viewer header, cookie and query string, with no caching, and responses still stream.
  • The gateway reads the stream token from x-coderhelm-stream-token, and falls back to Authorization: Bearer (auth::jwt::stream_token). CloudFront's signature now takes the Authorization header. The function still checks the token on every request.
  • The dashboard sends that header, plus the body's SHA-256 in x-amz-content-sha256, which Lambda requires of a signed POST (Send chat streams through the install's signed CloudFront path coderhelm#353, merged). selfhost/versions.json pins it (a95516a).
  • The split layout, CoderHelm's own deployment, keeps its URL and its bearer token.

Buckets (S3.5, S3.9, S3.13)

  • A new log bucket, <prefix>-logs<suffix>, in the storage stack:
    • SSE-S3, all public access blocked, TLS-only;
    • ACLs on with the bucket owner preferred, so CloudFront's standard logs can write;
    • logs expire after 90 days;
    • deleted with the stack: writes are refused first, then it is emptied.
  • The data, dashboard and sandbox buckets write server access logs to it, under s3/<name>/. Its policy lets S3 log delivery write for this account's <prefix>-* buckets.
  • The release bucket's policy is TLS-only now. It also has a lifecycle that aborts unfinished uploads, and so does the dashboard bucket.

CloudFront (CloudFront.5, CloudFront.15)

  • Standard logging goes to the log bucket, under cloudfront/, in the regions AWS enables by default (CLOUDFRONT_LOG_REGIONS). CloudFront delivers legacy logs to no bucket in an opt-in region, and turning them on there would fail the update. A native release's single template decides with a region condition (CloudFrontLogsRegion). Other installs decide at synth.
  • Viewers on a custom domain need TLSv1.2_2025.

Tables and sign-in (DynamoDB.2, DynamoDB.6, Cognito.3, Cognito.6)

  • Point-in-time recovery is on for waitlist, traces, checkpoints and billing-data.
  • Deletion protection is on for billing-data, traces and checkpoints. Traces and checkpoints are also retained like every other table. On a native install, protection follows KeepDataOnDelete.
  • The user pool has deletion protection (retainData, so it follows KeepDataOnDelete on a native install). Its password policy now needs a symbol, and temporary passwords last 7 days.
  • The gateway's password_fits checks the same rules. The sign-up error text already asked for a symbol.

Runtimes and email (Lambda.2, SES.3)

  • The MCP proxy runs on Node.js 22, built with esbuild's node22 target.
  • The install's SES configuration set, and the hosted mail relay's, send only over TLS.

Uninstaller and docs

  • The uninstaller also cleans up a leftover <prefix>-logs-<account> bucket.
  • docs/self-host/security.md, "Security Hub", lists each control and how it is met, and gives a reason for each accepted one. uninstall.md adds the log bucket.

Verification

  • infra: npm test, 166 passed. The new test/security-hub.test.ts covers the self-host, native and hosted templates. It checks:
    • the stream URL uses AWS_IAM and grants nothing public;
    • the OAC and both CloudFront permissions, scoped to the distribution;
    • the stream behaviours;
    • every bucket is TLS-only, has a lifecycle and writes access logs;
    • the log bucket's settings;
    • CloudFront's logging and TLS policy;
    • point-in-time recovery and deletion protection on every table;
    • the user pool;
    • the runtimes;
    • SES TLS.
  • cdk synth of config/selfhost.example.json with the real CLI: 11 templates, none mentioning the hosted domain. cfn-lint 1.58.0 passes on a native release's coderhelm.json, access.json and every part, and on infra/cfn.
  • No replacements. I diffed the templates against main for hosted prod, both self-host examples and a native release. The stateful resources change only in place:
    • tables: Replicas (point-in-time recovery, deletion protection);
    • user pool: DeletionProtection and Policies;
    • buckets: LoggingConfiguration and LifecycleConfiguration;
    • function URL: AuthType.
      No stateful resource is removed or replaced, and no create-only property changes. The two resources removed are the streaming URL's public AWS::Lambda::Permissions.
  • No new resource type, and no change to the boundary, deploy role or helper policies (the IAM simulator fixtures still match). The pinned deploy role can already make these changes:
    • s3:* on <prefix>-* buckets, including the ACL CloudFront's logging sets;
    • lambda:* on the install's functions;
    • the OAC calls.
  • cargo fmt --all, cargo clippy -p common -p gateway -p worker --all-targets -- -D warnings, and cargo test -q -p common -p gateway -p worker (3,938 passed). New gateway tests cover stream_token and the symbol rule.
  • Installer npm test, 171 passed. The MCP proxy builds with --target=node22.
  • Dashboard (PR updates stay true: description, risk, own review, generated types, e2e skips, content notes, questions, ticket comments #353): typecheck, lint, and 68 e2e tests on chat, plans and agent permissions, including the new request-header tests.
  • During the update, the stream answers 403 between the Streaming part's update and the Web part's (a few minutes). A tab opened before the update needs a reload.

The chat stream's function URL takes only calls CloudFront signs (AWS_IAM
and origin access control) on a single-origin install; the gateway reads the
stream token from x-coderhelm-stream-token, else a bearer token. Every bucket
is TLS-only with a lifecycle, and the data, dashboard and sandbox buckets and
the distribution write access logs to a new log bucket. Every table has
point-in-time recovery and deletion protection, the user pool has deletion
protection and a password policy that needs a symbol, the MCP proxy runs on
Node.js 22, SES sends only over TLS, and viewers on a domain need
TLSv1.2_2025. docs/self-host/security.md lists each control and the ones
accepted, with why.
CoderHelm/coderhelm a95516a sends the stream token in its own header and the
body's SHA-256, which the AWS_IAM function URL behind origin access control
needs.
Legacy standard logging delivers to no bucket in an opt-in region, and
turning it on there would fail the update. A native release's one template
decides by its region (a condition); any other install at synth.
@nambok
nambok merged commit fe47a53 into main Nov 10, 2026
10 checks passed
@nambok
nambok deleted the fix/security-hub branch November 10, 2026 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant